package code.example.base.util.concurrent.atomic;

import java.util.concurrent.atomic.AtomicReferenceArray;

public class TestAtomicReferenceArray {
    int capacity = 1024;
    AtomicReferenceArray atomicReferenceArray = new AtomicReferenceArray(capacity);
    public Object create(String key,Object obj){
        int hashCode = key.hashCode();
        int index = hashCode &  capacity;
        for(;;){
            Object result = atomicReferenceArray.get(index) ;
            if (result  != null ) {
                return result;
            }else if(atomicReferenceArray.compareAndSet(index,result,obj)){
                return obj;
            }
        }

    }
}
